//
//  HJUIDTipView.m
//  KaiChat
//
//  Created by lx on 2024/1/18.
//

#import "HJUIDTipView.h"
#import "QMUIButton.h"

@implementation HJUIDTipView {
    UIView * __weak _errorTipView;
    UIView * __weak _ableModifiedView;
    UIButton * __weak _closeButton;
}
 
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {

        [self clipsToBounds];

        UIView *errorTipView = [self addErrorTipView];
        [self addSubview:errorTipView];
        errorTipView.hidden = YES;
        [errorTipView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.offset(0);
        }];
   
        UIView *ableModifiedView = [self ableModifiedView];
        ableModifiedView.hidden = YES;
        [self addSubview:ableModifiedView];
        [ableModifiedView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.offset(0);
        }];
        
        _errorTipView = errorTipView;
        _ableModifiedView = ableModifiedView;
        
    }
    return self;
}

- (UIView *)addErrorTipView {
    UIView *view = [[UIView alloc] init];
    
    view.backgroundColor = UIColor.tj_FFF8F1Color;
    view.addCornerRadius(10);
    [view clipsToBounds];
    
    UIImageView *iconImageView = [UIImageView addToView:view];
    iconImageView.image = [UIImage imageNamed:@"warn_icon"];
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.centerY.offset(0);
        make.width.height.offset(20);
    }];
    
    UILabel *titleLabel = [UILabel lableWithSuperView:view font:UIFontMediumMake(12) color:UIColor.tj_FF5100Color title:@"At least 6 characters" textAlignment:NSTextAlignmentLeft];
    titleLabel.numberOfLines = 0;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.inset(10);
        make.left.equalTo(iconImageView.mas_right).offset(10);
    }];
    
    QMUIButton *closeButton = [QMUIButton addToView:view];
    [closeButton setImage:[UIImage imageNamed:@"tipClose"] forState:UIControlStateNormal];
    [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.inset(10);
        make.width.height.offset(20);
    }];
 
    _closeButton = closeButton;
    return view;
}

- (UIView *)ableModifiedView {
    UIView *view = [[UIView alloc] init];
    
    view.backgroundColor = UIColor.tj_F7FDFCColor;
    view.addCornerRadius(10);
    [view clipsToBounds];
    
    UIImageView *iconImageView = [UIImageView addToView:view];
    iconImageView.image = [UIImage imageNamed:@"uid_correct"];
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.centerY.offset(0);
        make.width.height.offset(20);
    }];
    
    UILabel *titleLabel = [UILabel lableWithSuperView:view font:UIFontMediumMake(12) color:UIColor.tj_3AB197Color title:@"UID is usable" textAlignment:NSTextAlignmentLeft];
    titleLabel.numberOfLines = 0;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.inset(10);
        make.left.equalTo(iconImageView.mas_right).offset(10);
        make.right.inset(42);
    }];
    
    return view;
}

- (void)setIsError:(BOOL)isError {
    _isError = isError;
    
    _ableModifiedView.hidden = isError;
    _errorTipView.hidden = !isError;
}


@end
